package com.cms.jy.draft.util;

import com.cms.jy.draft.entity.*;

import java.io.IOException;

/**
 * 草稿保存工具类
 * 负责将修改后的草稿保存到文件系统
 */
public class DraftSaver {
    
    /**
     * 保存草稿内容
     * @param draftContent 草稿内容
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveDraftContent(DraftContent draftContent, String basePath) throws IOException {
        String filePath = basePath + "/draft_content.json";
        DraftConfigWriter.writeDraftContent(draftContent, filePath);
    }
    
    /**
     * 保存草稿元信息
     * @param metaInfo 草稿元信息
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveDraftMetaInfo(DraftMetaInfo metaInfo, String basePath) throws IOException {
        String filePath = basePath + "/draft_meta_info.json";
        DraftConfigWriter.writeDraftMetaInfo(metaInfo, filePath);
    }
    
    /**
     * 保存草稿设置
     * @param settings 草稿设置
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveDraftSettings(DraftSettings settings, String basePath) throws IOException {
        String filePath = basePath + "/draft_settings";
        DraftConfigWriter.writeDraftSettings(settings, filePath);
    }
    
    /**
     * 保存草稿代理配置
     * @param agencyConfig 草稿代理配置
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveDraftAgencyConfig(DraftAgencyConfig agencyConfig, String basePath) throws IOException {
        String filePath = basePath + "/draft_agency_config.json";
        DraftConfigWriter.writeDraftAgencyConfig(agencyConfig, filePath);
    }
    
    /**
     * 保存草稿虚拟存储配置
     * @param virtualStore 草稿虚拟存储配置
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveDraftVirtualStore(DraftVirtualStore virtualStore, String basePath) throws IOException {
        String filePath = basePath + "/draft_virtual_store.json";
        DraftConfigWriter.writeDraftVirtualStore(virtualStore, filePath);
    }
    
    /**
     * 保存完整草稿
     * @param draftContent 草稿内容
     * @param metaInfo 草稿元信息
     * @param settings 草稿设置
     * @param agencyConfig 草稿代理配置
     * @param virtualStore 草稿虚拟存储配置
     * @param basePath 基础路径
     * @throws IOException IO异常
     */
    public static void saveCompleteDraft(DraftContent draftContent, DraftMetaInfo metaInfo, 
                                       DraftSettings settings, DraftAgencyConfig agencyConfig, 
                                       DraftVirtualStore virtualStore, String basePath) throws IOException {
        saveDraftContent(draftContent, basePath);
        saveDraftMetaInfo(metaInfo, basePath);
        saveDraftSettings(settings, basePath);
        saveDraftAgencyConfig(agencyConfig, basePath);
        saveDraftVirtualStore(virtualStore, basePath);
    }
}